Skip to content

test: integration tests for hook entry points (GIT-58)#27

Merged
TonyCasey merged 2 commits intomainfrom
tony/git-58-integration-tests-for-hook-entry-points
Feb 12, 2026
Merged

test: integration tests for hook entry points (GIT-58)#27
TonyCasey merged 2 commits intomainfrom
tony/git-58-integration-tests-for-hook-entry-points

Conversation

@TonyCasey
Copy link
Copy Markdown
Owner

@TonyCasey TonyCasey commented Feb 12, 2026

Summary

  • End-to-end integration tests for all hook entry points against real temp git repos
  • Tests git-mem hook session-start/stop/prompt-submit as child processes via spawnSync
  • Tests git-mem init-hooks --yes and --remove for file creation/cleanup
  • Shared helpers (helpers.ts) for running CLI, creating test repos, and config setup
  • Verifies other tools' hooks are preserved during install/remove

Closes GIT-58

Test plan

  • node --import tsx --test tests/integration/hooks/hook-session-start.test.ts — 4 pass
  • node --import tsx --test tests/integration/hooks/hook-session-stop.test.ts — 3 pass
  • node --import tsx --test tests/integration/hooks/hook-prompt-submit.test.ts — 3 pass
  • node --import tsx --test tests/integration/hooks/hook-init-hooks.test.ts — 6 pass
  • All 16 tests pass together
  • npm run pre-commit — type-check + lint clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added a comprehensive integration test infrastructure for hook end-to-end testing, including utilities to run hook commands, manage temporary repositories, and validate CLI behavior.
    • Added integration test coverage for init-hooks, prompt-submit, session-start, and session-stop scenarios, verifying install/remove flows, prompt behavior, memory-driven output, and session capture summaries across multiple conditions.

Add end-to-end integration tests exercising hooks as child processes
against real temp git repos:
- session-start: stdout with memories, stderr summary, empty store graceful
- session-stop: capture via liberate pipeline, summary output
- prompt-submit: context surfacing when enabled, silent when disabled
- init-hooks: file creation, correct schemas, remove cleanup, preserves
  other tools' hooks

Shared helpers use tsx binary to support cwd in temp directories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 12, 2026 21:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Adds integration test helpers and four end-to-end test suites for git-mem hooks (init-hooks, prompt-submit, session-start, session-stop). The helpers create and manage temporary git repos, run the CLI/hook entrypoints, and assert outputs and repository state.

Changes

Cohort / File(s) Summary
Integration Test Helpers
tests/integration/hooks/helpers.ts
New test utility module exposing IRunResult, runHook, runCli, createTestRepo, addCommit, writeGitMemConfig, and cleanupRepo; includes local git(...) wrapper and paths for tsx/CLI execution.
Hook Integration Tests
tests/integration/hooks/hook-init-hooks.test.ts, tests/integration/hooks/hook-prompt-submit.test.ts, tests/integration/hooks/hook-session-start.test.ts, tests/integration/hooks/hook-session-stop.test.ts
New end-to-end tests covering: install/remove behavior of init-hooks, prompt-submit enabled/disabled flows with memory store, session-start output when memories exist vs empty, and session-stop capture behavior across commits. Tests use temp repos and the new helpers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (2 files):

⚔️ tests/unit/infrastructure/di/container.test.ts (content)
⚔️ tests/unit/infrastructure/events/EventBus.test.ts (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding integration tests for hook entry points, with a specific reference to the issue (GIT-58).
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tony/git-58-integration-tests-for-hook-entry-points
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch tony/git-58-integration-tests-for-hook-entry-points
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@tests/integration/hooks/helpers.ts`:
- Around line 8-9: Consolidate the two separate imports from 'child_process'
into a single import statement: replace the two lines importing spawnSync and
execFileSync separately with one combined import that imports both spawnSync and
execFileSync from 'child_process' (target the existing import declarations for
spawnSync and execFileSync in tests/integration/hooks/helpers.ts).
- Around line 96-97: The current shallow merge at the config creation line
(using defaults, overrides, and hooks: { ...defaults.hooks, ...overrides })
replaces nested hook objects (e.g., sessionStart) and loses inner properties
like memoryLimit; change this to a deep merge for hooks so nested properties are
preserved — either call a deep-merge utility (e.g., lodash.merge) or add a small
recursive merge helper and use hooks: mergeDeep(defaults.hooks, overrides),
keeping the top-level defaults merging logic intact (referencing the variables
config, defaults, overrides and the hooks/sessionStart objects).

In `@tests/integration/hooks/hook-init-hooks.test.ts`:
- Around line 37-57: This test depends on settings.json created by a previous
spec and can flake if run alone; modify the test in hook-init-hooks.test.ts to
ensure idempotency by creating or initializing the settings before asserting:
check for settingsPath (join(workDir, '.claude', 'settings.json')) and if
missing call the same setup helper or CLI init used by the earlier test (the
helper or command that creates .claude/settings.json—use the existing setup
function or test titled "should create .claude/settings.json and .git-mem.json"
or its underlying initializer), then read and assert the hooks as currently
written so the test can run independently.

In `@tests/integration/hooks/hook-prompt-submit.test.ts`:
- Around line 44-53: The test manually writes a full .git-mem.json instead of
using the writeGitMemConfig helper; update
tests/integration/hooks/hook-prompt-submit.test.ts to call
writeGitMemConfig(repoDir, { promptSubmit: { enabled: true, recordPrompts:
false, surfaceContext: true } }) (and the similar call for the other case around
lines 93-101) and remove the manual JSON write; also fix writeGitMemConfig to
deep-merge nested hook objects (instead of the current shallow merge) so that
passing an overrides object like { promptSubmit: {...} } merges into existing
hooks.sessionStart/sessionStop defaults correctly.

Comment thread tests/integration/hooks/helpers.ts Outdated
Comment thread tests/integration/hooks/helpers.ts Outdated
Comment thread tests/integration/hooks/hook-init-hooks.test.ts
Comment thread tests/integration/hooks/hook-prompt-submit.test.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end integration coverage for git-mem’s Claude Code hook entry points by running the real CLI against temporary git repositories, validating stdout/stderr behavior and init-hooks install/remove semantics.

Changes:

  • Adds integration tests for git-mem hook session-start, session-stop, and prompt-submit executed via child processes.
  • Adds integration tests for git-mem init-hooks --yes and --remove, including preservation of non–git-mem hooks in .claude/settings.json.
  • Introduces shared integration helpers for creating temp repos, writing config, and spawning the CLI.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/integration/hooks/helpers.ts Shared utilities to create temp repos/config and spawn the CLI/hooks for integration tests.
tests/integration/hooks/hook-session-start.test.ts Verifies session-start hook behavior with/without stored memories (stdout/stderr + exit code).
tests/integration/hooks/hook-session-stop.test.ts Verifies session-stop hook runs end-to-end against a real repo and produces expected outputs.
tests/integration/hooks/hook-prompt-submit.test.ts Verifies prompt-submit surfaces context when enabled and is silent when disabled.
tests/integration/hooks/hook-init-hooks.test.ts Verifies init-hooks install/remove behavior and preserving other tools’ hooks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +19
const PROJECT_ROOT = resolve(__dirname, '../../..');
const CLI_PATH = resolve(PROJECT_ROOT, 'src/cli.ts');

// Use tsx binary from project node_modules — works even when cwd is a temp dir
const TSX_BIN = resolve(PROJECT_ROOT, 'node_modules/.bin/tsx');

Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TSX_BIN is hard-coded to node_modules/.bin/tsx, which is not portable (e.g. Windows uses tsx.cmd, and some environments won’t have an executable file at that path). Consider invoking the CLI via process.execPath with --import tsx (matching the repo’s test scripts) or resolving the tsx entrypoint via Node resolution so integration tests run reliably across platforms/environments.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged — this is a macOS/Linux-only CLI tool at the moment (git notes backend). The tsx binary approach was chosen because node --import tsx doesn't resolve when cwd is a temp directory outside the project root. If Windows support is needed later we can switch to process.execPath with a loader, but for now the binary path works reliably in CI and local dev.

Comment thread tests/integration/hooks/helpers.ts Outdated
Comment thread tests/integration/hooks/hook-init-hooks.test.ts Outdated
…helper (GIT-58)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@tests/integration/hooks/helpers.ts`:
- Around line 25-38: The runHook helper currently ignores a provided cwd in its
JSON input, so update runHook to read a cwd string (e.g., const { cwd } = input
or input.cwd) and pass it into the spawnSync options (alongside input, encoding,
timeout) so the spawned process runs in the intended working directory; locate
the runHook function that calls spawnSync with TSX_BIN and CLI_PATH and add the
cwd option only when it is a valid string to avoid changing behavior when not
provided.

In `@tests/integration/hooks/hook-prompt-submit.test.ts`:
- Around line 51-63: The test "should return context in stdout" uses runHook and
currently asserts that result.stdout includes any of "validate", "input", or
"security", which is flaky; update the assertion to check for a deterministic
indicator instead (for example a known memory snippet or a stable marker
inserted by the test fixture such as a specific sentence fragment or tag), by
replacing the loose includes(...) checks on result.stdout with a single assert
that result.stdout.includes('<expected memory fragment or marker>') so the test
reliably verifies the returned context from runHook('prompt-submit', ...).

Comment thread tests/integration/hooks/helpers.ts
Comment thread tests/integration/hooks/hook-prompt-submit.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants